# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Morteza NourelahiAlamdari <m@0t1.me>

pkgname=sqlfluff
pkgver=2.0.7
pkgrel=1
pkgdesc='A dialect-flexible and configurable SQL linter'
arch=('any')
url='https://www.sqlfluff.com'
license=('MIT')
depends=(
  'python'
  'python-appdirs'
  'python-cached-property'
  'python-chardet'
  'python-click'
  'python-colorama'
  'python-diff-cover'
  'python-jinja'
  'python-oyaml'
  'python-pathspec'
  'python-pytest'
  'python-regex'
  'python-tblib'
  'python-toml'
  'python-tqdm'
  'python-typing_extensions'
)
makedepends=(
  'git'
  'python-build'
  'python-wheel'
  'python-installer'
  'python-setuptools'
)
checkdepends=('python-hypothesis')
_commit='d19de0ecd16d298f9e3bfb91da122734c40c01e5'
source=("$pkgname::git+https://github.com/sqlfluff/sqlfluff.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  python \
    -m build \
    --wheel \
    --no-isolation
}

check() {
  cd "$pkgname"

  # install to temporary directory for access to sqlfluff executable
  python \
    -m installer \
    --destdir "$PWD/tmpdir" \
    dist/*.whl
  local PATH="$PWD/tmpdir/usr/bin:$PATH"

  # skip failing tests for now
  PYTHONPATH="$PWD/src:$PYTHONPATH" pytest \
    --ignore test/core/plugin_test.py \
    --ignore plugins \
    --deselect test/test_testing.py::test_rules__test_helper_has_variable_introspection
}

package() {
  cd "$pkgname"

  python \
    -m installer \
    --destdir "$pkgdir" \
    dist/*.whl

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.md
}
